package com.jsu.user.controller.v1;

import com.baomidou.mybatisplus.extension.api.R;
import com.jsu.user.service.impl.WebRuleServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.index.qual.SameLen;
import org.example.model.common.dtos.ResponseResult;
import org.example.model.user.pojo.Rule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/web/v1/rule")
@Slf4j
@Api(tags = "用户积分规则控制器")
public class WebRuleController {
    @Autowired
    private WebRuleServiceImpl webRuleService;
    @ApiOperation(value = "用户获取积分规则")
    @GetMapping("/get")
    public ResponseResult getRule(){
        return webRuleService.getRule();
    }

    @ApiOperation(value = "获取积分规则列表")
    @GetMapping("/list")
    public ResponseResult getRuleList(){
        return webRuleService.getRuleList();
    }

    @ApiOperation(value = "更新积分规则")
    @PostMapping("/update")
    public ResponseResult updateRule(@RequestBody Rule rule){
        return webRuleService.updateRule(rule);
    }

    @ApiOperation(value = "删除积分规则")
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteRule(@PathVariable int id){
        return webRuleService.deleteRule(id);
    }

    @ApiOperation(value = "用户签到")
    @PostMapping("/sign/{id}")
    public ResponseResult ruleSignIn(@PathVariable int id,@RequestHeader("token") String token){
        return webRuleService.ruleSignIn(id,token);
    }

    @ApiOperation(value = "添加积分规则")
    @PostMapping("/add")
    public ResponseResult addRule(@RequestBody Rule rule){
        return webRuleService.addRule(rule);
    }

    @ApiOperation(value = "模糊查询积分规则")
    @GetMapping("/search/{keyword}")
    public ResponseResult searchRule(@PathVariable String keyword) {
        return webRuleService.searchRule(keyword);
    }

    @ApiOperation(value = "批量删除积分规则")
    @DeleteMapping("/batchDelete")
    public ResponseResult batchDeleteRule(@RequestBody Integer[] ids) {
        log.info("批量删除积分规则，ids={}", ids[0]);
        return webRuleService.batchDeleteRule(ids);
    }

}
